﻿@using Blazorise.Docs.Services
@implements IDisposable
<BarItem>
    <BarLink To="pricing">Pricing</BarLink>
</BarItem>
<BarItem>
    <BarLink To="support">Support</BarLink>
</BarItem>
<BarItem>
    <BarLink To="account">Account</BarLink>
</BarItem>
<BarItem>
    <BarLink To="https://github.com/Megabit/Blazorise" Target="Target.Blank" aria-label="Star Blazorise on GitHub">
        <Div Display="Display.Flex.Row.Block.OnDesktop" Flex="Flex.Default.OnWidescreen.Flex.AlignItems.Center">
            <Icon Name="IconName.Star" IconStyle="IconStyle.Regular" IconSize="IconSize.Large" TextColor="TextColor.Warning"/>
            <Span Margin="Margin.Is2.FromStart" Display="Display.Block.OnMobile.None.OnDesktop.Block.OnWidescreen">
                Star us on GitHub
            </Span>
        </Div>
    </BarLink>
</BarItem>
<BarItem>
    <BarDropdown RightAligned>
        <BarDropdownToggle>
            @if ( ThemeService.IsDark )
            {
                <Icon Name="IconName.Moon" />
            }
            else if ( ThemeService.IsSystem )
            {
                <Icon Name="IconName.Adjust" />
            }
            else
            {
                <Icon Name="IconName.Sun" />
            }
        </BarDropdownToggle>
        <BarDropdownMenu>
            <BarDropdownItem Clicked="@(()=>ThemeService.SetLightTheme())" Flex="Flex.AlignItems.Center">
                <Icon Name="IconName.Sun" Margin="Margin.Is2.FromEnd" /> Light <Icon Name="IconName.Check" Margin="Margin.IsAuto.FromStart" Visibility="@(ThemeService.IsLight ? Visibility.Visible : Visibility.Invisible)" />
            </BarDropdownItem>
            <BarDropdownItem Clicked="@(()=>ThemeService.SetDarkTheme())" Flex="Flex.AlignItems.Center">
                <Icon Name="IconName.Moon" Margin="Margin.Is2.FromEnd" /> Dark <Icon Name="IconName.Check" Margin="Margin.IsAuto.FromStart" Visibility="@(ThemeService.IsDark ? Visibility.Visible : Visibility.Invisible)" />
            </BarDropdownItem>
            <BarDropdownItem Clicked="@(()=>ThemeService.SetSystemTheme())" Flex="Flex.AlignItems.Center">
                <Icon Name="IconName.Adjust" Margin="Margin.Is2.FromEnd" /> System <Icon Name="IconName.Check" Margin="Margin.IsAuto.FromStart" Visibility="@(ThemeService.IsSystem ? Visibility.Visible : Visibility.Invisible)" />
            </BarDropdownItem>
        </BarDropdownMenu>
    </BarDropdown>
</BarItem>
@code {
    [Inject] private ThemeService ThemeService { get; set; }

    protected override void OnInitialized()
    {
        ThemeService.ThemeChanged += OnThemeChanged;

        base.OnInitialized();
    }

    public void Dispose()
    {
        ThemeService.ThemeChanged -= OnThemeChanged;
    }

    void OnThemeChanged( object sender, string theme )
    {
        InvokeAsync(StateHasChanged);
    }
}